﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ColorSweet : MonoBehaviour {
    public enum ColorType
    {
        YELLOW,
        PINK,
        PERPLE,
        GREEN,
        RED,
        BLUE,
        COUNT,
        COLOR
        
    }
    [System.Serializable]
    public struct ColorSweets
    {
        public ColorType type;
        public Sprite sprite;
    };

    public ColorSweets[] colorSweet;
    public Dictionary<ColorType, Sprite> colorDic;

    private ColorType currentType;
    public ColorType CurrentType
    {
        get
        {
            return currentType;
        }
        set
        {
            SetColor(value);
        }
    }


    private SpriteRenderer colorSprite;


    public int NumColor()
    {
        return colorSweet.Length;
    }
    private void Awake()
    {
        colorSprite = transform.Find("SweetSprite").GetComponent<SpriteRenderer>();
        colorDic = new Dictionary<ColorType, Sprite>();
        for(int i = 0; i < colorSweet.Length; i++)
        {
            if (!colorDic.ContainsKey(colorSweet[i].type))
            {
                colorDic.Add(colorSweet[i].type, colorSweet[i].sprite);
            }
        }
    }


    public void SetColor(ColorType _type)
    {
        if (colorDic.ContainsKey(_type))
        {
            currentType = _type;
            colorSprite.sprite = colorDic[currentType];
        }
    }


}
